package com.yanqu.road.dao.impl.activity.snowgarden;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenDollConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SnowGardenDollConfigDaoImpl extends TempDao {

    private static String getSnowGardenDollConfigSql = "select * from `t_s_activity_snowgarden_doll` where `activityId`=?";

    public Map<Integer, SnowGardenDollConfig> getSnowGardenMapConfig(int activityId){
        Map<Integer, SnowGardenDollConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSnowGardenDollConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SnowGardenDollConfig snowGardenDollConfig = new SnowGardenDollConfig();
                snowGardenDollConfig.setActivityId(rs.getInt("activityId"));
                int id = rs.getInt("id");
                snowGardenDollConfig.setId(id);
                snowGardenDollConfig.setName(rs.getString("name"));
                snowGardenDollConfig.setDesc(rs.getString("desc"));
                snowGardenDollConfig.setTime(rs.getInt("time"));
                snowGardenDollConfig.setSkillName(rs.getString("skillName"));
                snowGardenDollConfig.setSkillDesc(rs.getString("skillDesc"));
                snowGardenDollConfig.setQuality(rs.getInt("quality"));
                snowGardenDollConfig.setPeriod(rs.getString("period"));
                map.put(id, snowGardenDollConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
